package com.hong.concurrent.chapter4;

/**
 * @Author csh
 * @Description
 * @Date 2018/6/30 12:26
 */
public abstract class ObServableRunnable implements Runnable{

    final protected  LifeCycleListener listener;

    public ObServableRunnable(final  LifeCycleListener listener) {
        this.listener = listener;
    }

    protected void notifyChange(final  RunnableEvent event){
        listener.onEvent(event);
    }

    public enum RunnableState{
        RUNNING,ERROR,DONE
    }

    public static class RunnableEvent{
        /*任何状态*/
        private final RunnableState state;
        private final Thread thread;
        private final Throwable cause;


        public RunnableEvent(RunnableState state, Thread thread, Throwable cause) {
            this.state = state;
            this.thread = thread;
            this.cause = cause;
        }

        public RunnableState getState() {
            return state;
        }

        public Thread getThread() {
            return thread;
        }

        public Throwable getCause() {
            return cause;
        }


    }
}
